package huawei.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View.MeasureSpec;
import android.widget.TextView;
import o.fkq.b;

public class HwTextView extends TextView {
    private StaticLayout ˊ;
    private float ˋ;
    private float ˎ;
    private TextPaint ˏ;
    private float ॱ;

    public HwTextView(Context context) {
        this(context, null);
    }

    public HwTextView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwTextView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˋ(context, attributeSet, i);
    }

    protected void onMeasure(int i, int i2) {
        ˎ(MeasureSpec.getSize(i), MeasureSpec.getSize(i2));
        super.onMeasure(i, i2);
    }

    private void ˋ(Context context, AttributeSet attributeSet, int i) {
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, b.ˏ, i, 0);
        this.ˋ = obtainStyledAttributes.getDimension(b.ˊ, 0.0f);
        this.ॱ = obtainStyledAttributes.getDimension(b.ˋ, 0.0f);
        obtainStyledAttributes.recycle();
        if (this.ˋ == 0.0f && this.ॱ == 0.0f && VERSION.SDK_INT >= 26) {
            this.ˋ = (float) getAutoSizeMinTextSize();
            this.ॱ = (float) getAutoSizeStepGranularity();
            setAutoSizeTextTypeWithDefaults(0);
        }
        this.ˏ = new TextPaint();
        this.ˏ.set(getPaint());
        this.ˎ = getTextSize();
    }

    public void setAutoTextInfo(int i, int i2, int i3) {
        Resources system;
        Context context = getContext();
        if (context == null) {
            system = Resources.getSystem();
        } else {
            system = context.getResources();
        }
        this.ˋ = TypedValue.applyDimension(i3, (float) i, system.getDisplayMetrics());
        this.ॱ = TypedValue.applyDimension(i3, (float) i2, system.getDisplayMetrics());
    }

    private void ˎ(int i, int i2) {
        int maxWidth = getMaxWidth();
        int maxHeight = getMaxHeight();
        if (maxWidth != -1 && maxWidth < i) {
            i = maxWidth;
        }
        if (maxHeight != -1 && maxHeight < i2) {
            i2 = maxHeight;
        }
        int totalPaddingLeft = (i - getTotalPaddingLeft()) - getTotalPaddingRight();
        if (totalPaddingLeft >= 0) {
            if (this.ˏ == null) {
                this.ˏ = new TextPaint();
            }
            this.ˏ.set(getPaint());
            if (this.ˋ > 0.0f && this.ॱ > 0.0f) {
                float f;
                float f2 = this.ˎ;
                CharSequence text = getText();
                TransformationMethod transformationMethod = getTransformationMethod();
                if (transformationMethod != null) {
                    text = transformationMethod.getTransformation(text, this);
                }
                this.ˏ.setTextSize(f2);
                float f3 = f2;
                f2 = this.ˏ.measureText(text.toString());
                while (f2 > ((float) totalPaddingLeft) && f3 > this.ˋ) {
                    f2 = f3 - this.ॱ;
                    this.ˏ.setTextSize(f2);
                    f3 = f2;
                    f2 = this.ˏ.measureText(text.toString());
                }
                if (f3 < this.ˋ) {
                    f = this.ˋ;
                } else {
                    f = f3;
                }
                setTextSize(0, f);
                ˏ(i2, i);
            }
        }
    }

    private void ˏ(int i, int i2) {
        int maxLines = getMaxLines();
        if (maxLines > 1) {
            int extendedPaddingBottom;
            int extendedPaddingTop;
            int totalPaddingLeft = (i2 - getTotalPaddingLeft()) - getTotalPaddingRight();
            if (VERSION.SDK_INT >= 26) {
                extendedPaddingBottom = getExtendedPaddingBottom();
                extendedPaddingTop = getExtendedPaddingTop();
            } else {
                extendedPaddingTop = 0;
                extendedPaddingBottom = 0;
            }
            int i3 = (i - extendedPaddingBottom) - extendedPaddingTop;
            if (i3 > 0) {
                this.ˊ = new StaticLayout(getText(), getPaint(), totalPaddingLeft, Alignment.ALIGN_NORMAL, getLineSpacingMultiplier(), getLineSpacingExtra(), false);
                extendedPaddingTop = this.ˊ.getLineCount();
                if (this.ˊ.getHeight() > i3 && extendedPaddingTop > 1 && extendedPaddingTop <= maxLines + 1) {
                    setMaxLines(extendedPaddingTop - 1);
                }
            }
        }
    }

    public void setAutoTextSize(float f) {
        setAutoTextSize(2, f);
    }

    public void setAutoTextSize(int i, float f) {
        Resources system;
        Context context = getContext();
        if (context == null) {
            system = Resources.getSystem();
        } else {
            system = context.getResources();
        }
        this.ˎ = TypedValue.applyDimension(i, f, system.getDisplayMetrics());
        super.setTextSize(i, f);
    }
}
